<?php
namespace app\user\model;

use think\Model;
use think\Request;

class UserLog extends Model
{
    protected $autoWriteTimestamp = true;
    protected $type = [
       
    ];
    protected $globalScope = ['shop_id'];
    
    public function scopeShop_id($query)
    {
        $query->where('shop_id', ShopId());
    }
    public function getClientAttr($value)
    {
        $status = [1=>'小程序',0=>'电脑'];
        return $status[$value];
    }
    //获取部门
    public function shop()
    {
        return $this->belongsTo(Shop::class,'shop_id','id')->bind(['shop_name'=>'name']);
    }
    
    //获取部门
    public function user()
    {
        return $this->belongsTo(User::class,'user_id','id');
    }
    public function getIpInfo($ip)
    {
        if(empty($ip)) $ip=get_client_ip();  //get_client_ip()为tp自带函数，如没有，自己百度搜索。此处就不重复复制了
        $url='http://ip.taobao.com/service/getIpInfo.php?ip='.$ip;
        $result = file_get_contents($url);
        $result = json_decode($result,true);
        if($result['code']!==0 || !is_array($result['data'])) return false;
        return $result['data'];
    }
    
    
    
}